<template>
  <el-row>
    <el-col :span="24">
      <h2>作业发布</h2>
      <el-divider />
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="作业标题">
          <el-input v-model="form.workTitle" />
        </el-form-item>
        <el-form-item label="学科科目">
          <el-select v-model="form.workDisciplineId" placeholder="请选择学科">
            <el-option label="python数据分析" value="1" />
            <el-option label="java" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="作业分数">
          <el-input v-model="form.wordFraction" placeholder="请输入最大分数" style="max-width: 12%" />
        </el-form-item>
        <!--        <el-form-item label="发起时间">-->
        <!--          <el-col :span="11">-->
        <!--            <el-date-picker v-model="form.date1" type="date" placeholder="选择日期" style="width: 100%;" />-->
        <!--          </el-col>-->
        <!--          <el-col class="line" :span="2">-</el-col>-->
        <!--          <el-col :span="11">-->
        <!--            <el-time-picker v-model="form.date2" placeholder="选择时间" style="width: 100%;" />-->
        <!--          </el-col>-->
        <!--        </el-form-item>-->
        <el-form-item label="起止日期">
          <el-time-select
            v-model="form.tjStart"
            placeholder="起始时间"
            :picker-options="{
              start: '08:30',
              step: '00:15',
              end: '18:30'
            }"
          />
          <el-time-select
            v-model="form.tjEnd"
            placeholder="结束时间"
            :picker-options="{
              start: '08:30',
              step: '00:15',
              end: '18:30',
              minTime: form.tjStart
            }"
          />
        </el-form-item>
        <el-form-item label="评阅设置">
          <el-button type="text" @click="dialogFormVisible = true">选择评阅方式</el-button>
          <el-row v-if="form.pyMethod == 1">
            <el-col :span="24">
              <p>教师评阅: 主讲老师评阅</p>
            </el-col>
          </el-row>
          <el-row v-if="form.pyMethod == 2">
            <el-col :span="24">
              学生评阅: 评阅份数(份/人)
              <el-input-number v-model="form.pyStudentNum" :min="1" :max="10" label="份数" />
            </el-col>
            <el-col :span="24">
              <el-time-select
                v-model="form.pyStart"
                placeholder="起始时间"
                :picker-options="{
                  start: '08:30',
                  step: '00:15',
                  end: '18:30'
                }"
              />
              <el-time-select
                v-model="form.pyEnd"
                placeholder="结束时间"
                :picker-options="{
                  start: '08:30',
                  step: '00:15',
                  end: '18:30',
                  minTime: form.pyStart
                }"
              />
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="作业内容">
          <el-input v-model="form.content" type="textarea" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">立即创建</el-button>
          <el-button>取消</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-dialog title="评阅方式" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="选择评阅方式" :label-width="formLabelWidth">
          <el-select v-model="form.pyMethod" placeholder="请选择评阅方式">
            <el-option label="师评" value="1" />
            <el-option label="学生自评" value="2" />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
      </div>
    </el-dialog>
  </el-row>

</template>

<script>

import request from '@/utils/request'

export default {
  name: 'Index',
  data() {
    return {
      form: {
        workTitle: '',
        workDisciplineId: '',
        // date1: '',
        // date2: '',
        // delivery: false,
        type: [],
        wordFraction: 0,
        // resource: '',
        content: '',
        tjStart: '',
        tjEnd: '',
        pyStart: '',
        pyEnd: '',
        // py: '',
        pyMethod: '',
        pyStudentNum: 1,
        userId: 1
      },
      dialogFormVisible: false,
      formLabelWidth: '120px'
    }
  },
  mounted() {
    var userId = localStorage.getItem('userId')
    this.form.userId = userId
  },
  methods: {
    onSubmit() {
      request.post('/AddWord', this.form).then((res) => {
        if (res.code === 200) {
          this.$message({
            message: res.msg,
            type: 'success'
          })
        } else {
          this.$message({
            message: res.msg,
            type: 'error'
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.el-textarea__inner{
  min-height: 120px !important;
}
</style>
